﻿using System.Collections.Generic;
using System.Threading.Tasks;
using MWS.Processing.Domain;
using MWS.Processing.Interfaces;

namespace MWS.Processing.Runners
{
    public class ProcessRunner : IProcessRunner
    {
        public IList<IProcessor> Processors { get; set; }

        public ProcessRunner(IList<IProcessor> processors)
        {
            Processors = processors;
        }

        public void Start()
        {
            Status = RunningStatus.Initializing;
            Parallel.ForEach(Processors, processor => processor.Start());
            Status = RunningStatus.Running;
        }

        public void Stop()
        {
            Status = RunningStatus.Stopping;
            Parallel.ForEach(Processors, processor => processor.Stop());
            Status = RunningStatus.Stopped;
        }

        public RunningStatus Status { get; set; }
    }
}